/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.base.db.impl;

import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.template.SqlMapDaoTemplate;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.yunhoo.base.model.Organization;
import com.yunhoo.sys.db.util.DbTool;
import com.yunhoo.base.db.dao.OrganizationDao;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Administrator
 */
public class OrganizationDaoImpl extends SqlMapDaoTemplate implements OrganizationDao {

    private static SqlMapClient sqlmap;
    private String nameSpace = "organization.";

    public OrganizationDaoImpl(DaoManager daoManager) {
        super(daoManager);
        sqlmap = DbTool.getSqlMapClient();
    }

    @Override
    public void insert(Organization org) throws SQLException {
        System.out.println(nameSpace + "insert");
        sqlmap.insert(nameSpace + "insert", org);
    }

    @Override
    public void update(Organization org) throws SQLException {
        System.out.println(nameSpace + "update");
        sqlmap.update(nameSpace + "update", org);
    }

    @Override
    public void delete(Organization org) throws SQLException {
        System.out.println(nameSpace + "delete");
        sqlmap.delete(nameSpace + "delete", org);
    }

    @Override
    public void deleteById(String orgCode) throws SQLException {
        System.out.println(nameSpace + "deleteById");
        sqlmap.delete(nameSpace + "deleteById", orgCode);
    }

    @Override
    public Organization queryById(String orgCode) throws SQLException {
        System.out.println(nameSpace + "queryById");
        return (Organization) sqlmap.queryForObject(nameSpace + "queryById", orgCode);
    }

    @Override
    public List<Organization> queryAll() throws SQLException {
        System.out.println(nameSpace + "queryAll");
        return sqlmap.queryForList(nameSpace + "queryAll");
    }

    @Override
    public void updateIsEnd(Organization org) throws SQLException {
        System.out.println(nameSpace + "updateIsEnd");
        sqlmap.update(nameSpace + "updateIsEnd", org);
    }

    @Override
    public Organization nameRepeatForInsert(Organization org) throws SQLException {
        System.out.println(nameSpace + "nameRepeatForInsert");
        return (Organization) sqlmap.queryForObject(nameSpace + "nameRepeatForInsert", org);
    }

    @Override
    public Organization nameRepeatForUpdate(Organization org) throws SQLException {
        System.out.println(nameSpace + "nameRepeatForUpdate");
        return (Organization) sqlmap.queryForObject(nameSpace + "nameRepeatForUpdate", org);
    }

    @Override
    public List<Organization> directSubNodes(Organization org) throws SQLException {
        System.out.println(nameSpace + "directSubNodes");
        return sqlmap.queryForList(nameSpace + "directSubNodes", org);
    }

    public static void main(String args[]) throws SQLException {
        sqlmap = DbTool.getSqlMapClient();
        List<Organization> orgli;
        orgli = sqlmap.queryForList("organization." + "queryAll");
        System.out.println("org : " + orgli);
    }
}
